﻿/// /////////////////////////////////////////////
// 单元名 : ProgressForm
// 作者 : Hawk
// 单元描述 :
// 日期 : 2023-09-15
/// /////////////////////////////////////////////

{$IFDEF FPC}
{$H+}
{$MODE DELPHI}
{$ENDIF}
unit ProgressForm;

interface

uses
{$IFnDEF FPC}
  Windows,
{$ELSE}
  LCLIntf, LCLType, LMessages,
{$ENDIF}
  Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
  TfrmProgressInfo = class(TForm)
    LabelProgressStr: TLabel;
    LabelProgress: TLabel;
  private
    { Private declarations }
    FShowTimerDeCount: integer;
  protected
    procedure WndProc(var mes: TMessage); override;
  public
    { Public declarations }
    procedure ShowProgress(str: UnicodeString; Progress, Time: integer);
  end;

implementation

const
  ID_TIMER_SHOWCOUNT = 1;

{$IFnDEF FPC}
  {$R *.dfm}
{$ELSE}
  {$R *.lfm}
{$ENDIF}
  { TfrmProgressInfo }

procedure TfrmProgressInfo.ShowProgress(str: UnicodeString; Progress, Time: integer);
begin
  LabelProgressStr.Caption := str;
  LabelProgressStr.Left := (ClientWidth - LabelProgressStr.Width) div 2;
  LabelProgress.Caption := '';
  LabelProgress.Left := (ClientWidth - LabelProgress.Width) div 2;
  if Time = 0 then
    Time := 5;
  FShowTimerDeCount := Time;
  SetTimer(Handle, ID_TIMER_SHOWCOUNT, 1000, nil);
  Show;
end;

procedure TfrmProgressInfo.WndProc(var mes: TMessage);
begin
  case mes.Msg of
    WM_TIMER:
      begin
        Dec(FShowTimerDeCount);
        if FShowTimerDeCount <= 0 then
        begin
          KillTimer(Handle, ID_TIMER_SHOWCOUNT);
          Hide;
        end;
      end;
  else
    inherited;
  end;
end;

end.
